﻿using System.Collections.Generic;

namespace Spectro.Cards
{
    /// <summary>
    /// Gamer for card game
    /// </summary>
    public class Gamer : IEssence
    {
        public Gamer(List<ICard> cards)
        {
            this.Wariors = new Warior[6];
            Health = 60;
            Cards = cards;
            Power = new MagicPower();
        }

        public List<ICard> Cards { get; set; } 

        public IEssence[] Wariors { get; set; }

        public string Name
        {
            get
            {
                return string.Empty;
            }
        }

        public int Health { get; set; }

        public MagicPower Power { get; set; }

        public IEnumerable<IAction> GetActions(Gamer attaker, Gamer defender)
        {
            var result = new List<IAction>();
            foreach (var warior in this.Wariors)
            {
                if (warior != null)
                {
                    result.AddRange(warior.GetActions(attaker, defender));
                }
            }
            return result;
        }

        public IEnumerable<IFilter> GetFilters(Gamer attaker, Gamer defender)
        {
            var result = new List<IFilter>();
            foreach (var warior in this.Wariors)
            {
                if (warior != null)
                {
                    result.AddRange(warior.GetFilters(attaker, defender));
                }
            }
            return result;
        }

        public virtual bool IsCanExecuteEction(IAction action, Gamer attaker, Gamer defender)
        {
            return true;
        }

        public virtual void AfterAttack(Gamer attaker, Gamer defender)
        {
            
        }

        public virtual IEssence Die(Gamer attaker, Gamer defender)
        {
            return null;
        }

        public void AddWarior(Warior warior, int position)
        {
            warior.Position = position;
            this.Wariors[position] = warior;
        }
    }
}
